import {reqGetTradeList, reqTradeInfo, reqUserAddress} from "@/api";

const state = {
    orderDetailList: {},
    userAddressList: [],
    tradeInfo: {}
}
// actions不能写错，否则派发不到这里的action
const actions = {

    // 获取订单列表
    async getTradeList({commit}, data) {
        const {page, limit} = data
        const result = await reqGetTradeList(page, limit);
        (result,'获取订单列表')
        if (result.code === 200) {
            commit('GETTRADLIST', result.data)
        }
    },

    // 获取用户地址信息
    async getUserAddress({commit}) {
        const result = await reqUserAddress();
        if (result.code === 200) {
            (result,'获取用户地址信息')
            commit('GETUSERADDRESS',result.data)
        }
    },

    // 获取交易页信息
    async getTradeInfo({commit}) {
        const result = await reqTradeInfo();
        if (result.code === 200) {
            commit('GETTRADEINFO', result.data)
        }
    }
}
const mutations = {
    GETTRADLIST(state, data) {
        state.orderDetailList = data
    },
    GETUSERADDRESS(state, data) {
        state.userAddressList = data
    },
    GETTRADEINFO(state, tradeInfo) {
        state.tradeInfo = tradeInfo
    }
}
const getters = {}

export default {
    state,
    actions,
    mutations,
    getters
}